﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace JqueryNet.FormControl.FormWebControl
{
    public class JCheckBox : JWebControl
    {
        CheckBox checkbox;
        public JCheckBox(CheckBox checkbox)
            : base(checkbox)
        {
            this.checkbox = checkbox;
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "checked":
                    Value = checkbox.Checked;return;
                case "text":
                    Value = checkbox.Text;return;
                case "tooltip":
                    Value = checkbox.ToolTip;return;
                default: base.Attr(key); return;
            }
        }

        public override void Attr(string key, string value)
        {
            bool f;
            bool.TryParse(value, out f);
            switch (key.ToLower())
            {
                case "checked":
                    checkbox.Checked = f; return;
                case "text":
                    checkbox.Text = value; return;
                case "tooltip":
                    checkbox.ToolTip = value; return;
                default: base.Attr(key, value); return;
            }
        }

        public override void Val()
        {
            Value = checkbox.Text;
        }

        public override void Val(string value)
        {
            checkbox.Text = value;
        }
    }
}
